#include("header.html")
<div class="container">
    <div class="box box-primary">
        <div class="box-header">
            <h4 class="box-title"><span class="fa fa-key"></span>找回密码</h4>
        </div>
        <div class="box-body">
            <form method="post" class="form-horizontal">
                <div class="form-group">
                    <div  id="error" style="color: red;margin-left: 40%;margin-bottom: 2%;display: none;"></div>
                    <label for="username" class="control-label col-lg-2 col-md-3 col-sm-2 col-xs-4">账号</label>
                    <div class="col-lg-10 col-md-9 col-sm-10">
                        <input name="username" id="username" class="form-control" placeholder="请输入账号" required onfocus="errorNone();">
                    </div>
                </div>
                <div class="form-group">
                    <label for="password" class="control-label col-lg-2 col-md-3 col-sm-2 col-xs-4">密码</label>
                    <div class="col-lg-10 col-md-9 col-sm-10">
                        <input name="password" id="password" class="form-control" placeholder="请输入新密码" type="password" required onfocus="errorNone();">
                    </div>
                </div>
                <div class="form-group">
                    <label for="get_back_tel" class="control-label col-lg-2 col-md-3 col-sm-2 col-xs-4 text-danger">预留号码</label>
                    <div class="col-lg-10 col-md-9 col-sm-10">
                        <input name="tel" id="get_back_tel" class="form-control" placeholder="输入预留号码（必填）" maxlength="11" required onfocus="errorNone();">
                    </div>
                </div>
                <div style="margin-top: 5px;" class="form-group">
                    <div class="col-lg-12">
                        <button type="submit" class="btn btn-success btn-block">确定</button>
                    </div>
                </div>
            </form>
            #include("sign.html")
        </div>
    </div>
</div>
<script>
    $('form').submit(function (e) {
        e.preventDefault();
        console.log($(this).serialize());

        if (checkPassword()) {
            $.post('/user/get_back', $(this).serialize(), function (data) {
                if (data.success) {
                    alert('SUCCESS: 找回成功！\n你的新密码是：'+$("#password").val());
                    location.href = "/user/login";
                } else {
                    alert('ERROR: ' + data.msg)
                }
            });
        }
    });

    function checkPassword() {
//        va;r flag = haveChinese($('#password').val());alert(flag)
        if($('#password').val().length<6){
            document.getElementById('error').innerText="密码长度不能小于6位！";
            document.getElementById('error').style.display='block';
            return 0;
        }
        else return 1;
    }
    function errorNone(){
        document.getElementById('error').style.display='none';
    }
</script>
</body>
</html>